# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=kiwiirc
_pkgname=KiwiIRC
pkgver=0.9.4
pkgrel=2
pkgdesc="A hand-crafted webirc client"
url="https://www.kiwiirc.com/"
# riscv64 blocked by nodejs
arch="noarch !riscv64"
license="AGPL-3.0"
depends="nodejs>=0.10.0"
makedepends="nodejs npm"
install="$pkgname.pre-install"
subpackages="$pkgname-doc"
pkgusers="kiwiirc"
pkggroups="kiwiirc"
source="$pkgname-$pkgver.tar.gz::https://github.com/prawnsalad/KiwiIRC/archive/v$pkgver.tar.gz
	kiwilauncher.patch
	kiwipath.patch
	$pkgname.initd
	$pkgname.confd"

builddir="$srcdir/KiwiIRC-$pkgver"

build() {
	npm -q install
	npm -q dedupe
}

package() {
	install -D -m644 config.example.js $pkgdir/etc/kiwiirc/config.js
	install -D -m755 kiwi $pkgdir/usr/bin/kiwi
	install -D -m644 package.json $pkgdir/usr/share/webapps/kiwiirc/package.json
	install -d -m755 $pkgdir/usr/lib/kiwiirc/server_modules
	install -d -m755 $pkgdir/var/lib/kiwiirc
	install -d -m775 $pkgdir/var/run/kiwiirc
	install -d -m644 $pkgdir/var/log/kiwiirc
	install -d -m755 $pkgdir/usr/share/webapps/kiwiirc/server
	install -d -m755 $pkgdir/usr/share/webapps/kiwiirc/node_modules

	cp -a client/* $pkgdir/var/lib/kiwiirc
	cp -a node_modules $pkgdir/usr/share/webapps/kiwiirc/
	cp -a server $pkgdir/usr/share/webapps/kiwiirc
	cp -a server_modules $pkgdir/usr/lib/kiwiirc

	chown -R $pkgusers:$pkggroups "$pkgdir"/etc/kiwiirc
	chown -R $pkgusers:$pkggroups "$pkgdir"/usr/lib/kiwiirc
	chown -R $pkgusers:$pkggroups "$pkgdir"/usr/share/webapps/kiwiirc
	chown -R $pkgusers:$pkggroups "$pkgdir"/var/lib/kiwiirc
	chown $pkgusers:$pkggroups "$pkgdir"/var/run/kiwiirc

	install -D -m755 $srcdir/$pkgname.initd $pkgdir/etc/init.d/$pkgname
	install -D -m644 $srcdir/$pkgname.confd $pkgdir/etc/conf.d/$pkgname
	install -D -m644 LICENSE.txt "$pkgdir"/usr/share/doc/$pkgname/LICENSE.txt
}

sha512sums="81034d4b1d6af93bd2fbacd302c0780996b87bbf0b936b61abb1ca04fb97939d956bf4704ada63766a4da04feb56957abf141ed74fff02fd7db237b6272a6ac4  kiwiirc-0.9.4.tar.gz
2b2b61d579fe73ba59c05b3bf9a8ac1bc43225ad414ab34474746731a443c56431ddc9156005a7d3890c65e2344c882d8731c1c36b7a07af0c7014fd4d37e811  kiwilauncher.patch
1bc8829398d1311384f8411bd65f6231831d2f24728d779f97a99b5e7e46758771c36b5daba215fe6508c728162bfbb22fdaa3be2b44988d59c53804e7005c40  kiwipath.patch
a0612b562313eaa6eb2f4fafab2d40ce4784685c8a14e57a5eae8c9126cab3370957dc0a56dace370e10ddb02bda01800063baf6fa66b8159d9f99c06ac85c39  kiwiirc.initd
416b807dee290b0d55020fd980dbf232615f173899d13fe859834cdb61af96a30c5edbeafa35e290cb9d9ed9695ae53abfc876fb4b73687dabfcb3467046a304  kiwiirc.confd"
